{% extends 'layout/manage.html' %}
{% block css %}

    <style type="text/css">
        .container .btn-primary {
            margin-top: 10px;
            margin-bottom: 20px;
        }

        .panel-body {
            padding: 0;
            display: flex;
            flex-direction: row;
            justify-content: left;
            align-items: flex-start;
            flex-wrap: wrap;
        }

        .panel-body .item {
            border-radius: 6px;
            width: 228px;
            border: 1px solid #dddddd;
            margin: 20px 10px;

        }

        .panel-body .item:hover {
            border: 1px solid #f0ad4e;
        }

        .panel-body .item .title {
            height: 104px;
            color: white;
            display: flex;
            justify-content: center;
            align-items: center;
            border-top-left-radius: 6px;
            border-top-right-radius: 6px;
            font-size: 15px;
            text-decoration: none;
        }

        .panel-body .item .info {
            padding: 10px 10px;

            display: flex;
            justify-content: space-between;

            border-bottom-left-radius: 6px;
            border-bottom-right-radius: 6px;
            color: #8c8c8c;

        }

        .panel-body .item .info a {
            text-decoration: none;
        }

        .panel-body .item .info .fa-star {
            font-size: 18px;
        }

        .color-radio label {
            margin-left: 0;
            padding-left: 0;
        }

        .color-radio input[type="radio"] {
            display: none;
        }

        .color-radio input[type="radio"] + .cycle {
            display: inline-block;
            height: 25px;
            width: 25px;
            border-radius: 50%;
            border: 2px solid #dddddd;
        }

        .color-radio input[type="radio"]:checked + .cycle {
            border: 2px solid black;
        }
    </style>

{% endblock css %}
{% block content %}

    <div class="container">
        <a class="btn btn-primary" data-toggle="modal" data-target="#addModal"><i class="fa fa-plus"
                                                                                  aria-hidden="true"></i> 创建项目</a>

        <!-- Modal -->
        <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title" id="myModalLabel">创建项目</h4>
                    </div>
                    <div class="modal-body">
                        {#表单#}
                        <form id="addForm">
                            {% csrf_token %}
                            {% for field in form %}
                                <div class="form-group">
                                    <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                    {{ field }}
                                    <span class="error-msg"></span>
                                </div>
                            {% endfor %}
                        </form>

                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="button" id="btn-Submit" class="btn btn-primary">确定</button>
                    </div>
                </div>
            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-flag" aria-hidden="true"></i> 星标
            </div>
            <div class="panel-body">
                {% for item in project_dict.star %}
                    <div class="item">
                        <a href="{% url 'web:manage:dashboard' item.value.id %}" class="title"
                           style="background-color: {{ item.value.get_color_display }};">{{ item.value.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'web:project_unstar' project_type=item.type project_id=item.value.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #f0ad4e;"></i>
                                </a>
                                <span>{{ item.value.create_user.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.value.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-bars" aria-hidden="true"></i> 我创建的
            </div>
            <div class="panel-body">
                {% for item in project_dict.create %}
                    <div class="item">
                        <a href="{% url 'web:manage:dashboard' item.id %}" class="title"
                           style="background-color: {{ item.get_color_display }};">{{ item.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'web:project_star' project_type='user_create' project_id=item.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #7b7b77;"></i>
                                </a>
                                <span>{{ item.create_user.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>

        <div class="panel panel-default">
            <div class="panel-heading">
                <i class="fa fa-joomla" aria-hidden="true"></i> 我参与的
            </div>
            <div class="panel-body">
                {% for item in project_dict.join %}
                    <div class="item">
                        <a href="{% url 'web:manage:dashboard' item.id %}" class="title"
                           style="background-color: {{ item.get_color_display }};">{{ item.name }}</a>
                        <div class="info">
                            <div>
                                <a href="{% url 'web:project_star' project_type='user_join' project_id=item.id %}">
                                    <i class="fa fa-star" aria-hidden="true" style="color: #7b7b77;"></i>
                                </a>
                                <span>{{ item.create_user.username }}</span>
                            </div>
                            <div>
                                <i class="fa fa-user-o" aria-hidden="true"></i>
                                <span>{{ item.join_count }}</span>
                            </div>
                        </div>
                    </div>
                {% endfor %}
            </div>
        </div>
    </div>


{% endblock content %}

{% block js %}

    <script type="text/javascript">
        $(function () {

            $('#btn-Submit').click(function () {
                // 获取所有数据
                params = $('#addForm').serialize();
                $.ajax({
                    url: '{% url 'web:project_list' %}',
                    type: 'post',
                    data: params,
                    dataType: 'json'
                }).done(function (data) {
                    console.log(data.msg);
                    if (data.code === 200) {
                        // 主动刷新页面
                        location.reload();
                    } else {
                        $.each(data.msg, function (key, value) {
                            console.log(key + "-----" + value);
                            $('#id_' + key).next().text(value[0])
                        });
                    }
                }).fail(function () {
                    console.log("网络超时");
                });
            });
        })
    </script>

{% endblock js %}